package br.ufpb.di.knowledgetv.sqtv.modules;

import br.ufpb.di.knowledgetv.sqtv.utils.Data;
import br.ufpb.di.knowledgetv.sqtv.utils.RDFDatabase;
import br.ufpb.di.knowledgetv.sqtv.utils.SPARQLUtils;
import com.hp.hpl.jena.query.ResultSet;
import org.springframework.stereotype.Component;

/**
 * User: manoel
 * Date: 28/04/13
 */
@Component
public class LocalSearchModule implements SQTVModule {

    private RDFDatabase database = RDFDatabase.getInstance();

    @Override
    public Data execute(Data data) {
        String keywords = (String) data.getData("keywords");
        ResultSet result;
        String sparql = SPARQLUtils.readFileSparql(getClass().getResource("/sparqls/local_search.sparql").getPath(),keywords );
        result = database.searchBySparql(sparql);

        if(result.hasNext()) {
            data.addData("local_results", result);
        }
        return data;
    }
}
